#include<func.h>

void clean(void *p)
{
    printf("%ld is cleaning\n",(long)p);
}

void *func(void *p)
{
    pthread_cleanup_push(clean,(void*)1);
    pthread_cleanup_push(clean,(void*)2);
    
    printf("child thread:sleep\n");
    sleep(1);
    printf("child thread:wake up\n");
   
    pthread_cleanup_pop(1);
    pthread_cleanup_pop(1);
}

int main()
{
    pthread_t pthid;
    int ret;
    ret = pthread_create(&pthid,NULL,func,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    pthread_cancel(pthid);
   
    long threadRet;
    pthread_join(pthid,(void**)&threadRet);
    printf("child exit code :%ld\n",threadRet);
    return 0;
}
